package org.example.web.admin.schedule;


import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.example.model.entity.LeaseAgreement;
import org.example.model.enums.LeaseStatus;
import org.example.web.admin.service.LeaseAgreementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class ScheduleTask {

    @Autowired
    private LeaseAgreementService leaseAgreementService;

    @Scheduled(cron = "0 0 20 * * ? ")
    public void updateLeaseStatus() {
        LambdaUpdateWrapper<LeaseAgreement> wrapper = new LambdaUpdateWrapper<>();
        //设置修改条件 la.lease_end_date<date()
        wrapper.lt(LeaseAgreement::getLeaseEndDate,new Date());
        //AND la.status IN (2,5)
        wrapper.in(LeaseAgreement::getStatus,
                              LeaseStatus.SIGNED,
                          LeaseStatus.WITHDRAWING);
        //设置修改的值
        wrapper.set(LeaseAgreement::getStatus, LeaseStatus.EXPIRED);
        //调用
        leaseAgreementService.update(wrapper);
    }

}
